import os
import torch
import numpy as np
import torchvision.utils as vutils
import matplotlib.pyplot as plt
import os

import matplotlib.pyplot as plt
import numpy as np
import torch
import torchvision.utils as vutils

os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'

netG=torch.load('./netg1000.pt')
print("----开始生成图片-----")
nz=100
device=torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
# 创建一批噪声数据用来生成
img_list=[]
for a in range(1000):
    fixed_noise = torch.randn(size=(1, nz, 1, 1), device=device)  
    fake=netG(fixed_noise).detach().cpu()
    img_list.append(vutils.make_grid(fake,padding=2,normalize=True))
    i=vutils.make_grid(fake,padding=2,normalize=True)
    fig=plt.figure(figsize=(8,8))
    plt.imshow(np.transpose(i,(1,2,0)))
    plt.axis("off")
    root="/Users/mazaiting/Data/program/gitee/gan-x/202409/temp/dcgan/image/"  ##生成图片存放路径
    plt.savefig(root+str(a)+"_"+".png",bbox_inches='tight',pad_inches = -0.1)
    plt.close(fig)
  
